home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / artemis / artsrc2 / usrfnc.c < prev    next >
Text File  |  1994-06-01  |  6KB  |  289 lines

  1. typedef    unsigned int    uint;
  2.  
  3. char    EGB_work[1536];
  4.  
  5. /*
  6. void    ginit()
  7.     {
  8.     KYB_init();
  9.     EGB_init(EGB_work, 1536);
  10.     }
  11. */
  12.  
  13. /*===============================================
  14.                 キーボード関係
  15. ===============================================*/
  16.  
  17. char    key_get()
  18.     {
  19.     uint    code, encode;
  20.     for (;;) {
  21.         code = KYB_read( 0, &encode );
  22.         if ( (code & 0xffff) == 0xffff  &&  (encode & 0xff00) == 0xff00 )
  23.             continue;
  24.         break;
  25.         }
  26.     return (char) code;
  27.     }
  28.  
  29. int        key_chk()        /* キー入力があるなら 1   なければ 0 */
  30.     {
  31.     uint    code, encode;
  32.     int        chrcnt;
  33.     code = KYB_inpchk( &chrcnt, &encode );
  34.     if ( chrcnt == 0 )
  35.         return 0;
  36.     else
  37.         return 1;
  38.     }
  39.  
  40. char    key_read()        /* キー入力があれば そのコード なければ 0 */
  41.     {
  42.     if (key_chk())
  43.         return key_get();
  44.     else
  45.         return 0;
  46.     }
  47.  
  48. void    key_clrbuf()
  49.     {
  50.     KYB_clrbuf();
  51.     }
  52.  
  53. /*====================================================
  54.                 グラフィック関係
  55. ====================================================*/
  56.  
  57. void    grp_init()
  58.     {
  59.     EGB_init ( EGB_work, 1536 );
  60.     }
  61.  
  62. void    grp_clr()
  63.     {
  64.     EGB_clearScreen( EGB_work );
  65.     }
  66.  
  67. void    grp_putstr( x, y, str, col )
  68.     int        x, y;        /* 文字列の表示位置 */
  69.     char    *str;        /* シフト JIS 文字列(100バイト以内) */
  70.     int        col;
  71.     {
  72.     char    parabuf[110];
  73.     EGB_color(EGB_work, 0, col);
  74.     * (short*) ( parabuf     ) = x;
  75.     * (short*) ( parabuf + 2 ) = y + 16;
  76.     * (short*) ( parabuf + 4 ) = strlen( str );
  77.     strcpy( parabuf+6, str );
  78.     EGB_sjisString( EGB_work, parabuf );
  79.     }
  80.  
  81. void    grp_pset( x, y, col, mode )
  82.     int        x, y;
  83.     int        col;
  84.     int        mode;
  85.     {
  86.     short para[3];
  87.     para[0] = 1;
  88.     para[1] = x;
  89.     para[2] = y;
  90.     EGB_writeMode( EGB_work, mode );
  91.     EGB_color( EGB_work, 0, col );
  92.     EGB_pset( EGB_work, (char*) para );
  93.     }
  94.  
  95. void    grp_line( x1, y1, x2, y2, col, mode )
  96.     int        x1, y1, x2, y2;
  97.     int        col;
  98.     int        mode;
  99.     {
  100.     short para[5];
  101.     para[0] = 2;
  102.     para[1] = x1;
  103.     para[2] = y1;
  104.     para[3] = x2;
  105.     para[4] = y2;
  106.     EGB_writeMode( EGB_work, mode );
  107.     EGB_color( EGB_work, 0, col );
  108.     EGB_connect( EGB_work, (char*) para );
  109.     }
  110.  
  111. void    grp_boxline( x1, y1, xlen, ylen, col, mode )
  112.     int        x1, y1;
  113.     int        xlen, ylen;
  114.     int        col;
  115.     int        mode;
  116.     {
  117.     short    para[4];
  118.     para[0] = x1;
  119.     para[1] = y1;
  120.     para[2] = x1 + xlen -1;
  121.     para[3] = y1 + ylen -1;
  122.     EGB_writeMode( EGB_work, mode );
  123.     EGB_paintMode( EGB_work, 0x202 );
  124.     EGB_color( EGB_work, 0, col );
  125.     EGB_rectangle( EGB_work, (char*) para );
  126.     }
  127.  
  128. void    grp_boxfill( x1, y1, xlen, ylen, col, mode )
  129.     int        x1, y1;
  130.     int        xlen, ylen;
  131.     int        col;
  132.     int        mode;
  133.     {
  134.     short    para[4];
  135.     para[0] = x1;
  136.     para[1] = y1;
  137.     para[2] = x1 + xlen -1;
  138.     para[3] = y1 + ylen -1;
  139.     EGB_writeMode( EGB_work, mode );
  140.     EGB_paintMode( EGB_work, 0x222 );
  141.     EGB_color( EGB_work, 0, col );
  142.     EGB_color( EGB_work, 2, col );
  143.     EGB_rectangle( EGB_work, (char*) para );
  144.     }
  145.  
  146. int        grp_getWrtpage()
  147.     {
  148.     return (int) EGB_getWritePage( EGB_work, 0 );
  149.     }
  150.  
  151. void    grp_setWrtpage( page )
  152.     int        page;
  153.     {
  154.     EGB_writePage( EGB_work, page );
  155.     }
  156.  
  157. void    grp_copy( sx1, sy1, sxlen, sylen, sp, dx1, dy1, dp, mode )
  158.     int        sx1, sy1, sxlen, sylen;
  159.     int        dx1, dy1;
  160.     int        sp, dp;
  161.     int        mode;
  162.     {
  163.     int        n, sx2, sy2, dmy, nowpage;
  164.     char    para[18], para2[8];
  165.     nowpage = grp_getWrtpage();
  166.     grp_setWrtpage( sp );
  167.     sx2 = sy1 + sxlen - 1;
  168.     sy2 = sy1 + sylen - 1;
  169.     WORD(para + 0) = 4;
  170.     WORD(para + 2) = sx1;
  171.     WORD(para + 4) = sy1;
  172.     WORD(para + 6) = sx1;
  173.     WORD(para + 8) = sy2;
  174.     WORD(para + 10) = sx2;
  175.     WORD(para + 12) = sy2;
  176.     WORD(para + 14) = sx2;
  177.     WORD(para + 16) = sy1;
  178.     n = 0x80;
  179.     EGB_region( EGB_work, &n, &dmy, &dmy, &dmy, &dmy, &dmy, para );
  180.     para2[0] = dp;
  181.     para2[1] = 0;
  182.     WORD(para2 + 2) = dx1 - sx1;
  183.     WORD(para2 + 4) = dy1 - sy1;
  184.     EGB_copy( EGB_work, 0, para2, NULL );
  185.     EGB_writePage( EGB_work, (int) nowpage );
  186.     }
  187.  
  188. void    grp_setplt( plt, rgb )
  189.     int        plt;
  190.     int        rgb;    /* bit23-16:赤  bit15-8:緑  bit7-0:青 */
  191.     {
  192.     char    para[12];
  193.     DWORD(para + 0) = 1;
  194.     DWORD(para + 4) = plt;
  195.     BYTE(para +  8) = (  rgb        & 0xff );
  196.     BYTE(para +  9) = ( (rgb >>  8) & 0xff );
  197.     BYTE(para + 10) = ( (rgb >> 16) & 0xff );
  198.     BYTE(para + 11) = 0;
  199.     EGB_palette( EGB_work, 0, para );
  200.     }
  201.  
  202. int        grp_getplt( plt )    /* ret : bit23-16:赤  bit15-8:緑  bit7-0:青  */
  203.     int        plt;
  204.     {
  205.     char    pltdat[4+8*256], *p;
  206.     int        ret;
  207.     EGB_getPalette( grp_getWrtpage(), pltdat );
  208.     p = pltdat + 4 + 8 * plt + 4;
  209.     ret = *p  |  ((int)*(p+1) << 16)  |  ((int)*(p+2) << 8);
  210.     return ret;
  211.     }
  212.  
  213. void    grp_getblk( x1, y1, xlen, ylen, buf )
  214.     int        x1, y1, xlen, ylen;
  215.     char    *buf;
  216.     {
  217.     char    para[14];
  218.     DWORD(para + 0) = (unsigned long) ( buf + 4 );
  219.     WORD(para + 4) = 0;
  220.     WORD(para + 6) = x1;
  221.     WORD(para + 8) = y1;
  222.     WORD(para + 10) = x1 + xlen - 1;
  223.     WORD(para + 12) = y1 + ylen - 1;
  224.     WORD(buf + 0) = xlen;
  225.     WORD(buf + 2) = ylen;
  226.     EGB_getBlock( EGB_work, para );
  227.     }
  228.  
  229. void    grp_putBlk( data, x1, y1 )
  230.     char    *data;
  231.     int        x1, y1;
  232.     {
  233.     char    para[14];
  234.     DWORD(para + 0) = (unsigned long) ( data + 4 );
  235.     WORD(para + 4) = 0;
  236.     WORD(para + 6) = x1;
  237.     WORD(para + 8) = y1;
  238.     WORD(para + 10) = x1 + (*(int*)  data   ) - 1;
  239.     WORD(para + 12) = y1 + (*(int*) (data+2)) - 1;
  240.     EGB_putBlock( EGB_work, 0, para );
  241.     }
  242.  
  243. int        grp_point ( x, y )
  244.     int        x, y;
  245.     {
  246.     int        ret;
  247.     EGB_point( EGB_work, 0, x, y, &ret);
  248.     return ret;
  249.     }
  250.  
  251. void    grp_mode ( int mode )
  252.     {
  253.     EGB_resolution( EGB_work, 0, mode );
  254.     if ( 1 <= mode && mode <= 11 )
  255.         EGB_resolution( EGB_work, 1, mode );
  256.     }
  257.  
  258. void    grp_mode2 ( int mode )
  259.     {
  260.     EGB_resolution( EGB_work, 1, mode );
  261.     }
  262.  
  263. void    grp_dispPos ( int x, int y )
  264.     {
  265.     EGB_displayStart( EGB_work, 1, x, y );
  266.     }
  267.  
  268. int        grp_getMode()
  269.     {
  270.     int page, p0,p1;
  271.     page = grp_getWrtpage();
  272.     EGB_getResolution( &p0, &p1 );
  273.     return ( page == 0  ?  p0 : p1 );
  274.     }
  275.  
  276. void    grp_scrZoom( int xrate, int yrate )
  277.     {
  278.     static struct { int x,y } resolution[] =
  279.         { { 640,400 },  { 640,200 }, { 640,480 }, { 640,400 },
  280.           { 256,256 },  { 256,256 }, { 256,240 }, { 256,240 },
  281.           { 360,240 },  { 320,240 }, { 320,240 },
  282.           { 640,480 },  { 640,400 }, { 720,480 },
  283.           { 320,480 },  { 320,480 }, { 512,480 }, { 512,480 } };
  284.     int mode;
  285.     EGB_displayStart( EGB_work, 2, xrate, yrate );
  286.     mode = grp_getMode() - 1;
  287.     EGB_displayStart( EGB_work, 3, resolution[mode].x, resolution[mode].y );
  288.     }
  289.